import java.lang.*;
import java.io.*;
public class ReqRawMaterials
 {     
          
   private InputStreamReader ir=new InputStreamReader(System.in);
	private BufferedReader br,br1;
	private FileOutputStream fos;
	private	PrintStream ps; 
	private FileReader frs;
           InvUpdate up=new InvUpdate(); 
            public void rawMaterialsReqPerProduct(int pid,String ivid[],int j,String pname)
                          {
                                							int s1[]=new int[4];
                                String id,stock[]=new String[20],name[]=new String[20],s;  
                 	        String cline[]=new String[10];
                                int id1[]= new int[20],i=0,total;System.out.println("test");
                                try
                             {
                                
                                frs=new FileReader("InventoryItem.txt");
                                br=new BufferedReader(frs);
                                
                                                 while((s=br.readLine()) != null)
			                          {
			 	                   cline=s.split(",");
                                                   id=cline[0];
                                                   id1[i]=Integer.parseInt(id);
                                                   name[i]=cline[1];
                               	                   stock[i]=cline[5];
                                                    i++;
                               		       }   
                               System.out.println("Raw Materials REquvired for manfacturing  unit product "+pname);
                               System.out.println("---------------------------------------------------------------");
                                    for(int n=0;n<j;n++)
                                      {
                                        System.out.println("Enter quantity of raw material  " + name[n] + " for unit " +pname+ " are:");
                                         br1=new BufferedReader(ir);
                                         s1[n]=Integer.parseInt(br1.readLine());                                         
                                       }  
		                     System.out.println("Enter total auantity Product " +pname+" to be manufactured:");
                                     total=Integer.parseInt(br1.readLine());
                                     System.out.println("Raw Materials REquvired for manfacturing  product "+pid+"  are:");
                                     System.out.println("---------------------------------------------------------------");
                                     System.out.println("\n  Rawmaterials    Quantity       ");
		             	     System.out.println("-------------------------------------------");
                                     for(int n=0;n<j;n++)
                                      {
                                        s1[n]*=total;
                                     System.out.println(  "\t"+name[n]+"        "+(s1[n]));
                                       }
                                    up.transaction(name,s1,j);
	                	}
		                catch(Exception ex)
		                   {
	                 		System.out.println("Some exceptions occured...");
			                System.out.println("Could not generate the daily transaction report...!");	
		                    }
			
                                             
                           }






            public void invList()
                {
                        String id,desc,rmrq,unitprice,stock,s,name;
		        String cline[]=new String[10];
                        String rm[]=new String[10], a[]=new String[10]; 
                        int s1,id1,j,x;		
                        System.out.println("\n enter product id:");
                           try
                             {
                                br1=new BufferedReader(ir);
                                s1=Integer.parseInt(br1.readLine());
                                frs=new FileReader("Item.txt");
                                br=new BufferedReader(frs);
                                while((s=br.readLine()) != null)
			      {
				cline=s.split(",");
				id=cline[0];
                                name=cline[1];
                                x=Integer.parseInt(id);
				rmrq=cline[3];
				stock=cline[5];
                                rm=rmrq.split(";");
                               if(x==s1)
                                  {                                
                                     j=rm.length;
                                     for(int k=0;k<j;k++)
                                       {
                                          a[k]=rm[k];
                                          
                                       } 
                                         rawMaterialsReqPerProduct(x,a,j,name);
                                                                           
                                   }
                                    
                                   
                              	}	
	
		}
		catch(Exception ex)
		{
			System.out.println("Some exceptions occured...");
			System.out.println("Could not generate the daily transaction report...!");	
		}
			
                  }
   
   
   
}